<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>【原创】NodeJs从入门到实战 | 大前端技术分享</title><meta name="author" content="凡尘"><meta name="copyright" content="凡尘"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="作为一名热爱学习的前端工程师，想要获得更大的成长，除了积累原生JavaScript的相关知识，还是有必要掌握后端开发的，这样是从一个全端开发工程师彻底转变成大前端的一个必经之路！">
<meta property="og:type" content="article">
<meta property="og:title" content="【原创】NodeJs从入门到实战">
<meta property="og:url" content="http://example.com/posts/undefined/index.html">
<meta property="og:site_name" content="大前端技术分享">
<meta property="og:description" content="作为一名热爱学习的前端工程师，想要获得更大的成长，除了积累原生JavaScript的相关知识，还是有必要掌握后端开发的，这样是从一个全端开发工程师彻底转变成大前端的一个必经之路！">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/03f34d3f6f914347905ce6e7a2f5a4b1~tplv-k3u1fbpfcp-zoom-1.image">
<meta property="article:published_time" content="2023-02-23T08:08:32.400Z">
<meta property="article:modified_time" content="2023-03-03T09:39:05.390Z">
<meta property="article:author" content="凡尘">
<meta property="article:tag" content="Nodejs">
<meta property="article:tag" content="后端">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/03f34d3f6f914347905ce6e7a2f5a4b1~tplv-k3u1fbpfcp-zoom-1.image"><link rel="shortcut icon" href="/assets/img/favicon.png"><link rel="canonical" href="http://example.com/posts/undefined/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><script>(adsbygoogle = window.adsbygoogle || []).push({
  google_ad_client: 'ca-pub-6311121231731422',
  enable_page_level_ads: 'true'
});</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '【原创】NodeJs从入门到实战',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-03-03 17:39:05'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/atom.xml" title="大前端技术分享" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/assets/img/logo.png" onerror="onerror=null;src='/assets/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-compass"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-compass"></i><span> 项目</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/project/vue/"><i class="fa-fw fas fa-cog"></i><span> vue系列</span></a></li><li><a class="site-page child" href="/html/project/react/"><i class="fa-fw fas fa-cog"></i><span> react系列</span></a></li><li><a class="site-page child" href="/html/project/mobile/"><i class="fa-fw fas fa-cog"></i><span> 移动端系列</span></a></li><li><a class="site-page child" href="/html/project/visual/"><i class="fa-fw fas fa-cog"></i><span> 三维可视化</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-star"></i><span> 收藏</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/collect/development/"><i class="fa-fw fas fa-cog"></i><span> 开发</span></a></li><li><a class="site-page child" href="/html/collect/design/"><i class="fa-fw fas fa-cog"></i><span> 设计</span></a></li><li><a class="site-page child" href="/html/collect/tool/"><i class="fa-fw fas fa-cog"></i><span> 工具</span></a></li><li><a class="site-page child" href="/html/collect/live/"><i class="fa-fw fas fa-cog"></i><span> 生活</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book"></i><span> 读书</span></a></li><li><a class="site-page child" href="/bangumi/"><i class="fa-fw fas fa-tv"></i><span> 追番</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-heart"></i><span> 关于</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/about/"><i class="fa-fw fa fa-id-card"></i><span> 简历</span></a></li><li><a class="site-page child" href="/atom.xml"><i class="fa-fw fas fa-rss"></i><span> 订阅</span></a></li><li><a class="site-page child" href="/html/messageboard/"><i class="fa-fw fas fa-comment-dots"></i><span> 留言</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/03f34d3f6f914347905ce6e7a2f5a4b1~tplv-k3u1fbpfcp-zoom-1.image')"><nav id="nav"><span id="blog-info"><a href="/" title="大前端技术分享"><img class="site-icon" src= "" data-lazy-src="/assets/img/logo.png"/><span class="site-name">大前端技术分享</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-compass"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-compass"></i><span> 项目</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/project/vue/"><i class="fa-fw fas fa-cog"></i><span> vue系列</span></a></li><li><a class="site-page child" href="/html/project/react/"><i class="fa-fw fas fa-cog"></i><span> react系列</span></a></li><li><a class="site-page child" href="/html/project/mobile/"><i class="fa-fw fas fa-cog"></i><span> 移动端系列</span></a></li><li><a class="site-page child" href="/html/project/visual/"><i class="fa-fw fas fa-cog"></i><span> 三维可视化</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-star"></i><span> 收藏</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/collect/development/"><i class="fa-fw fas fa-cog"></i><span> 开发</span></a></li><li><a class="site-page child" href="/html/collect/design/"><i class="fa-fw fas fa-cog"></i><span> 设计</span></a></li><li><a class="site-page child" href="/html/collect/tool/"><i class="fa-fw fas fa-cog"></i><span> 工具</span></a></li><li><a class="site-page child" href="/html/collect/live/"><i class="fa-fw fas fa-cog"></i><span> 生活</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book"></i><span> 读书</span></a></li><li><a class="site-page child" href="/bangumi/"><i class="fa-fw fas fa-tv"></i><span> 追番</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-heart"></i><span> 关于</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/html/about/"><i class="fa-fw fa fa-id-card"></i><span> 简历</span></a></li><li><a class="site-page child" href="/atom.xml"><i class="fa-fw fas fa-rss"></i><span> 订阅</span></a></li><li><a class="site-page child" href="/html/messageboard/"><i class="fa-fw fas fa-comment-dots"></i><span> 留言</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">【原创】NodeJs从入门到实战</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-02-23T08:08:32.400Z" title="发表于 2023-02-23 16:08:32">2023-02-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-03-03T09:39:05.390Z" title="更新于 2023-03-03 17:39:05">2023-03-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>8分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="【原创】NodeJs从入门到实战"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="NodeJs从入门到实战"><a href="#NodeJs从入门到实战" class="headerlink" title="NodeJs从入门到实战"></a>NodeJs从入门到实战</h1><h5 id="作为一名热爱学习的前端工程师，想要获得更大的成长，除了积累原生JavaScript的相关知识，还是有必要掌握后端开发的，这样是从一个全端开发工程师彻底转变成大前端的一个必经之路！"><a href="#作为一名热爱学习的前端工程师，想要获得更大的成长，除了积累原生JavaScript的相关知识，还是有必要掌握后端开发的，这样是从一个全端开发工程师彻底转变成大前端的一个必经之路！" class="headerlink" title="作为一名热爱学习的前端工程师，想要获得更大的成长，除了积累原生JavaScript的相关知识，还是有必要掌握后端开发的，这样是从一个全端开发工程师彻底转变成大前端的一个必经之路！"></a>作为一名热爱学习的前端工程师，想要获得更大的成长，除了积累原生JavaScript的相关知识，还是有必要掌握后端开发的，这样是从一个全端开发工程师彻底转变成大前端的一个必经之路！</h5><p><img src= "" data-lazy-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/03f34d3f6f914347905ce6e7a2f5a4b1~tplv-k3u1fbpfcp-zoom-1.image"></p>
<h2 id="项目背景"><a href="#项目背景" class="headerlink" title="项目背景"></a>项目背景</h2><p>由于我平时对前端领域比较感兴趣，所以也曾开发过属于自己的个人网站，从Hexo脚手架搭建的博客站，到前后端分离的个人网站，以及后面所接触到的unicloud云开发，这其中也渐渐对nodejs技术有了更进一步的了解。</p>
<p>目前负责公司的一个可视化平台的后台服务器项目，从最初的技术选型到一步一步的搭建，测试，到最终部署到Linux系统上，以及后期的迭代更新，也收获满满。</p>
<h2 id="技术架构"><a href="#技术架构" class="headerlink" title="技术架构"></a>技术架构</h2><p>因为是团队开发，我才用前后端分离的方式，具体技术栈如下：<br>服务端：NodeJs + Koa + sequelize + sqlite3<br>部署上线：pm2<br>代码管理： git</p>
<p>服务端技术架构图：<br><img src= "" data-lazy-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/32441bb936064a03a5c24d8b224cb3fb~tplv-k3u1fbpfcp-zoom-1.image"></p>
<h3 id="技术架构说明"><a href="#技术架构说明" class="headerlink" title="技术架构说明"></a>技术架构说明</h3><ul>
<li>这里我们采用node社区比较轻量的服务端框架Koa，然后服务端中间件有:   <ul>
<li>koa-static 提供静态资源访问，具体用途在项目实现细节里面会详细介绍</li>
<li>koa-body 处理请求报文，让koa可以方便的拿到post/put的数据</li>
<li>koa2-cors 本地联调时通过cors方式处理跨域问题</li>
<li>multer 用来处理文件上传</li>
<li>koa-router 用来编写服务端路由和api</li>
<li>koa-send 用于处理文件下载</li>
<li>axios HttpAPI请求工具, 这里是辅助前端进行第三方跨域请求</li>
<li>sequelize Node的ORM框架Sequelize来操作数据库，用于将关系数据库映射到对象上，然后进行的封装。</li>
</ul>
</li>
</ul>
<h5 id="上面就是我们web服务端主要使用的中间件，对于每一块如何去组织和架构，包括自己实现错误校验中间件，我会在后面一一介绍，由于写服务端的过程中也查阅了很多资料，如有不足或需要优化的地方，欢迎交流。"><a href="#上面就是我们web服务端主要使用的中间件，对于每一块如何去组织和架构，包括自己实现错误校验中间件，我会在后面一一介绍，由于写服务端的过程中也查阅了很多资料，如有不足或需要优化的地方，欢迎交流。" class="headerlink" title="上面就是我们web服务端主要使用的中间件，对于每一块如何去组织和架构，包括自己实现错误校验中间件，我会在后面一一介绍，由于写服务端的过程中也查阅了很多资料，如有不足或需要优化的地方，欢迎交流。"></a>上面就是我们web服务端主要使用的中间件，对于每一块如何去组织和架构，包括自己实现错误校验中间件，我会在后面一一介绍，由于写服务端的过程中也查阅了很多资料，如有不足或需要优化的地方，欢迎交流。</h5><h3 id=""><a href="#" class="headerlink" title=""></a></h3><h3 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">model-sequelize/</span><br><span class="line">|</span><br><span class="line">+- .vscode/无</span><br><span class="line">|  |</span><br><span class="line">|  +- launch.json &lt;-- VSCode 配置文件</span><br><span class="line">|</span><br><span class="line">+- controller/接口函数</span><br><span class="line">|  +- applys.js &lt;-- 应用接口函数</span><br><span class="line">|  +- node_util.js &lt;-- 通用接口函数</span><br><span class="line">|  +- project.js &lt;-- 项目管理接口函数</span><br><span class="line">|  ……</span><br><span class="line">|</span><br><span class="line">+- lib/请求响应处理封装</span><br><span class="line">|  +- return.js &lt;-- 过滤响应</span><br><span class="line">| </span><br><span class="line">+- util/工具库</span><br><span class="line">|  +- init</span><br><span class="line">|  +- model</span><br><span class="line">|  </span><br><span class="line">+- view/前端静态代码托管</span><br><span class="line">|  +- </span><br><span class="line">| </span><br><span class="line">+- models/ &lt;-- 存放所有数据表映射关系</span><br><span class="line">|  +- project.js &lt;-- 项目管理</span><br><span class="line">|  ……</span><br><span class="line">|</span><br><span class="line">+- db.js &lt;-- 如何定义Model</span><br><span class="line">|</span><br><span class="line">+- model.js &lt;-- 如何导入Model</span><br><span class="line">|</span><br><span class="line">+- database.js &lt;-- 初始化数据库</span><br><span class="line">|</span><br><span class="line">+- database.sqlite &lt;-- sqlite3数据库文件</span><br><span class="line">|</span><br><span class="line">+- server.js &lt;-- 业务代码(总入口)</span><br><span class="line">|</span><br><span class="line">+- server.json &lt;-- 业务配置项</span><br><span class="line">|</span><br><span class="line">+- package.json &lt;-- 项目描述文件</span><br><span class="line">|</span><br><span class="line">+- node_modules/ &lt;-- npm安装的所有依赖包</span><br></pre></td></tr></table></figure>

<h2 id="常用功能精讲"><a href="#常用功能精讲" class="headerlink" title="常用功能精讲"></a>常用功能精讲</h2><h3 id="sequelize"><a href="#sequelize" class="headerlink" title="sequelize"></a>sequelize</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">在没有sequelize之前，nodejs调用数据表，需要手写晦涩难懂的sql语句。</span><br><span class="line">而sequelize采用底层封装的思路，将数据表抽象成为对象，然后通过API进行实现增删改查。</span><br><span class="line">就如同vue解放了原生dom操作一般，有木有很方便。</span><br><span class="line">// 连接数据库</span><br><span class="line">const sequelize = new Sequelize(&#123;</span><br><span class="line">    host: &#x27;localhost&#x27;,</span><br><span class="line">    dialect: &#x27;sqlite&#x27;,</span><br><span class="line">    // timezone: &#x27;+08:00&#x27;,</span><br><span class="line">    pool: &#123;</span><br><span class="line">        max: 5,</span><br><span class="line">        min: 0,</span><br><span class="line">        acquire: 30000,</span><br><span class="line">        idle: 10000</span><br><span class="line">    &#125;,</span><br><span class="line">    storage: &#x27;database.sqlite&#x27;,</span><br><span class="line">    operatorsAliases: false</span><br><span class="line">&#125;);</span><br><span class="line">// 数据表建立 例子：</span><br><span class="line">module.exports = db.defineModel(&quot;user&quot;, &#123;</span><br><span class="line">    username: db.Sequelize.STRING,</span><br><span class="line">    password: db.Sequelize.STRING,</span><br><span class="line">    status: db.Sequelize.STRING,</span><br><span class="line">    token: db.Sequelize.STRING, // 保存至前端的加密信息 暂时由status+时间戳组成</span><br><span class="line">    wechat_sceneId:db.Sequelize.INTEGER, // 微信小程序所加载的场景id</span><br><span class="line">&#125;, &#123;</span><br><span class="line">    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名</span><br><span class="line">    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users</span><br><span class="line">    freezeTableName: true</span><br><span class="line">&#125;)</span><br><span class="line">// 多表关联建立 例子：</span><br><span class="line">// 关联一对多表查询</span><br><span class="line">applys.belongsTo(projects, &#123;</span><br><span class="line">    foreignKey:</span><br><span class="line">        &#x27;projectId&#x27;, targetKey: &#x27;id&#x27;</span><br><span class="line">&#125;);</span><br><span class="line">// 数据表的查询操作(其中model是我对所有数据表对象的封装)</span><br><span class="line">const userList=async ()=&gt;&#123;</span><br><span class="line">    let results = await model.user.findAll()</span><br><span class="line">    return results</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>最后想了解更多关于sequelize的使用，可以前往廖雪峰大佬的个人网站学习。<br><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.liaoxuefeng.com/wiki/1022910821149312/1101571555324224">##sequelize</a></p>
<h3 id="supervisor"><a href="#supervisor" class="headerlink" title="supervisor"></a>supervisor</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">在开发过程中的一个热更新插件supervisor</span><br></pre></td></tr></table></figure>

<h2 id="打包上线-打包成应用"><a href="#打包上线-打包成应用" class="headerlink" title="打包上线/打包成应用"></a>打包上线/打包成应用</h2><h3 id="进程常驻pm2"><a href="#进程常驻pm2" class="headerlink" title="进程常驻pm2"></a>进程常驻pm2</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">npm install -g pm2</span><br><span class="line">$ pm2 start app.js # 启动app.js应用程序</span><br><span class="line">$ pm2 start app.js -i 4        # cluster mode 模式启动4个app.js的应用实例</span><br><span class="line"># 4个应用程序会自动进行负载均衡</span><br><span class="line">$ pm2 start app.js --name=&quot;api&quot; # 启动应用程序并命名为 &quot;api&quot;</span><br><span class="line">$ pm2 start app.js --watch      # 当文件变化时自动重启应用</span><br><span class="line">$ pm2 start script.sh          # 启动 bash 脚本</span><br><span class="line">$ pm2 list                      # 列表 PM2 启动的所有的应用程序</span><br><span class="line">$ pm2 monit                    # 显示每个应用程序的CPU和内存占用情况</span><br><span class="line">$ pm2 show [app-name]          # 显示应用程序的所有信息</span><br><span class="line">$ pm2 logs                      # 显示所有应用程序的日志</span><br><span class="line">$ pm2 logs [app-name]          # 显示指定应用程序的日志</span><br><span class="line">$ pm2 flush                       # 清空所有日志文件</span><br><span class="line">$ pm2 stop all                  # 停止所有的应用程序</span><br><span class="line">$ pm2 stop 0                    # 停止 id为 0的指定应用程序</span><br><span class="line">$ pm2 restart all              # 重启所有应用</span><br><span class="line">$ pm2 reload all                # 重启 cluster mode下的所有应用</span><br><span class="line">$ pm2 gracefulReload all        # Graceful reload all apps in cluster mode</span><br><span class="line">$ pm2 delete all                # 关闭并删除所有应用</span><br><span class="line">$ pm2 delete 0                  # 删除指定应用 id 0</span><br><span class="line">$ pm2 scale api 10              # 把名字叫api的应用扩展到10个实例</span><br><span class="line">$ pm2 reset [app-name]          # 重置重启数量</span><br><span class="line">$ pm2 startup                  # 创建开机自启动命令</span><br><span class="line">$ pm2 save                      # 保存当前应用列表</span><br><span class="line">$ pm2 resurrect                # 重新加载保存的应用列表</span><br><span class="line">$ pm2 update                    # Save processes, kill PM2 and restore processes</span><br><span class="line">$ pm2 generate                  # Generate a sample json configuration file</span><br><span class="line">pm2文档地址：http://pm2.keymetrics.io/docs/usage/quick-start/</span><br></pre></td></tr></table></figure>

<h3 id="mysql数据库连接功能相关知识"><a href="#mysql数据库连接功能相关知识" class="headerlink" title="mysql数据库连接功能相关知识"></a>mysql数据库连接功能相关知识</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">开启本地数据库局域网访问</span><br><span class="line">1、更新root账户的权限。打开mysql命令行窗口，输入</span><br><span class="line"></span><br><span class="line">grant all privileges on *.* to root@&quot;%&quot; identified by &#x27;abc&#x27; with grant option;  flush privileges;</span><br><span class="line"></span><br><span class="line">上述语句的完整模板为：</span><br><span class="line"></span><br><span class="line">grant all privileges on 库名.表名 to &#x27;用户名&#x27;@&#x27;IP地址&#x27; identified by &#x27;密码&#x27; with grant option;</span><br><span class="line"></span><br><span class="line">flush privileges;</span><br><span class="line"></span><br><span class="line">测试，没有问题。</span><br><span class="line"></span><br><span class="line">2、创建一个新账户，如guest，并将可被访问的主机定义为%，即所有主机都可访问该账户。</span><br><span class="line"></span><br><span class="line">测试，没有问题。</span><br><span class="line">参考：</span><br><span class="line">https://jingyan.baidu.com/article/6dad50755e3dd1a123e36ec4.html</span><br></pre></td></tr></table></figure>

<h3 id="docker打包镜像"><a href="#docker打包镜像" class="headerlink" title="docker打包镜像"></a>docker打包镜像</h3><ul>
<li>window上要使用docker,可以使用docker desktop工具<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">安装和运行docker desktop</span><br><span class="line">测试demo</span><br><span class="line">执行步骤1-clone  克隆仓库镜像</span><br><span class="line">执行步骤2-build 编译</span><br><span class="line">执行步骤3-run</span><br></pre></td></tr></table></figure></li>
</ul>
<ul>
<li><p>创建配置项</p>
<ul>
<li>Dockerfile</li>
</ul>
 <figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">FROM node:12.13.0</span><br><span class="line"></span><br><span class="line"># Create app directory</span><br><span class="line">WORKDIR /usr/src/app</span><br><span class="line"></span><br><span class="line"># Install app dependencies</span><br><span class="line"># A wildcard is used to ensure both package.json AND package-lock.json    are copied</span><br><span class="line"># where available (npm@5+)</span><br><span class="line">COPY package*.json ./</span><br><span class="line"></span><br><span class="line">RUN yarn install</span><br><span class="line">#RUN npm install --registry=https://registry.npm.taobao.org</span><br><span class="line"># If you are building your code for production</span><br><span class="line">#RUN npm ci --only=production</span><br><span class="line"></span><br><span class="line"># Bundle app source</span><br><span class="line">COPY . .</span><br><span class="line"></span><br><span class="line">EXPOSE 3000</span><br><span class="line">CMD [ &quot;node&quot;, &quot;server.js&quot; ]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ul>
<li>dockerignore<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">.git</span><br><span class="line">.svn</span><br><span class="line">node_modules</span><br><span class="line">public</span><br><span class="line">static/model</span><br><span class="line">database.sqlite</span><br><span class="line">npm-debug.log</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<ul>
<li><p>编译打包服务端项目</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">  编译</span><br><span class="line">  docker build -t yanyufanchen/node-web-app .    </span><br><span class="line">node-web-app为打包的镜像名称  可以用:用户名/镜像名</span><br><span class="line">查看所有镜像</span><br><span class="line">docker images</span><br><span class="line">修改标签</span><br><span class="line">docker tag IMAGEID(镜像id) REPOSITORY:TAG（用户名/镜像名：标签）</span><br><span class="line">运行镜像</span><br><span class="line">docker run -p 3000:3000 -d 镜像名      映射端口49160:原有端口8080</span><br><span class="line">推送远程仓库</span><br><span class="line">docker push 镜像名称:标签</span><br><span class="line">删除镜像</span><br><span class="line">docker rmi -f 241c2cc33dde(镜像名称)</span><br><span class="line">查看容器</span><br><span class="line">docker ps</span><br><span class="line">停止容器</span><br><span class="line">docker stop</span><br><span class="line">删除容器</span><br><span class="line">docker rm -f</span><br></pre></td></tr></table></figure>

<ul>
<li>遇到的问题<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">安装docker desktop工具后出现提示”wsl2 installation is incomplete“</span><br><span class="line">原因：是没有安装linux在windows的子系统，可以在window store上下载debian工具</span><br><span class="line">解决方案：https://www.jiloc.com/45016.html</span><br><span class="line">1、安装debian</span><br><span class="line">2、启动debian</span><br><span class="line">3、注册账号密码 </span><br><span class="line">依然没有解决，安装wsl更新包</span><br><span class="line">https://www.cnblogs.com/xiluhua/p/14120713.html</span><br><span class="line">https://github.com/xiluhua/docker-desktop</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="代码混淆-uglify-es混淆"><a href="#代码混淆-uglify-es混淆" class="headerlink" title="代码混淆 uglify-es混淆"></a>代码混淆 uglify-es混淆</h3><p>安装</p>
<p>From NPM for use as a command line app:</p>
<p><code>npm install uglify-es -g</code></p>
<p>From NPM for programmatic use:</p>
<p><code>npm install uglify-es</code></p>
<p>使用</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">混用多个混淆属性选项：</span><br><span class="line">uglifyjs example.js -c -m --mangle-props regex=/_$/,reserved=[bar_]</span><br><span class="line">混淆并输出到指定目录下</span><br><span class="line">uglifyjs text2.js -o out/text2.js  -c -m --mangle-props regex=/_$/,reserved=[bar_]</span><br></pre></td></tr></table></figure>
<p>地址</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">uglify-js只能混淆es5以下</span><br><span class="line">参考中文文档</span><br><span class="line">http://www.suoniao.com/article/52</span><br><span class="line">uglify-es可以混淆es6</span><br><span class="line">https://github.com/mishoo/UglifyJS/tree/harmony</span><br></pre></td></tr></table></figure>

<h3 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h3><ul>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.jianshu.com/p/b988ce30bac3?from=singlemessage">koa学习</a></li>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.pengwang.xyz/">我的大前端个人网站</a></li>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="http://www.ptbird.cn/koa-body.html">关于中间件koa-body</a></li>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/duninet/article/details/103047040">文件上传</a></li>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.cnblogs.com/mordom/archive/2018/01/23/8337337.html">pkg 打包node应用</a></li>
<li><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.cnblogs.com/vipzhou/p/6559991.html">制作测试api文档</a></li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">凡尘</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/posts/undefined/">http://example.com/posts/undefined/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">大前端技术分享</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Nodejs/">Nodejs</a><a class="post-meta__tags" href="/tags/%E5%90%8E%E7%AB%AF/">后端</a></div><div class="post_share"><div class="social-share" data-image="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/03f34d3f6f914347905ce6e7a2f5a4b1~tplv-k3u1fbpfcp-zoom-1.image" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/posts/undefined/" title="【转载】前端项目集成Vite配置一览无余！ - 掘金"><img class="cover" src= "" data-lazy-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/db5838b3f060400fa4e09edd7d51b3c3~tplv-k3u1fbpfcp-zoom-crop-mark:3024:3024:3024:1702.awebp?" onerror="onerror=null;src='/assets/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">【转载】前端项目集成Vite配置一览无余！ - 掘金</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="lv-container" data-id="city" data-uid="MTAyMC81ODA5NC8zNDU1Nw=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/assets/img/logo.png" onerror="this.onerror=null;this.src='/assets/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">凡尘</div><div class="author-info__description">真理无穷，一寸欢喜。</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">7</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div><a id="card-info-btn" target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/yanyufanchen"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/yanyufanchen" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:yanyufanchen@gmail.com" rel="external nofollow noreferrer" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://juejin.cn/user/3554079798734622" rel="external nofollow noreferrer" target="_blank" title="掘金"><i class="fa-duotone fa-address-card"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content"><div id='ipInfo'></div><script src="/assets/js/getBrowserInfo.js"></script><script>function geoip(obj) {var address = obj.country === obj.city ? obj.city : obj.country + ' ' + obj.city; var addr = obj.city ? address : obj.country;document.getElementById("ipInfo").innerHTML = '访客地址：<i class="fas fa-map-marked"></i> <a target="_blank" rel="noopener external nofollow noreferrer" href="https://whatismyipaddress.com/ip/' + obj.ip + '">' + addr + '</a><br/>' + '访客 IP：<i class="fas fa-at"></i> <a target="_blank" rel="noopener external nofollow noreferrer" href="https://get.geojs.io/v1/ip/geo.js/">' + obj.ip + '</a><br>浏览器：<i class="fab fa-chrome"></i> <span style="color:#2196f3">' + getBrowserInfo() + '</span>';}</script><script src= "https://get.geojs.io/v1/ip/geo.js"></script></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#NodeJs%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E6%88%98"><span class="toc-number">1.</span> <span class="toc-text">NodeJs从入门到实战</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%BD%9C%E4%B8%BA%E4%B8%80%E5%90%8D%E7%83%AD%E7%88%B1%E5%AD%A6%E4%B9%A0%E7%9A%84%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%B8%88%EF%BC%8C%E6%83%B3%E8%A6%81%E8%8E%B7%E5%BE%97%E6%9B%B4%E5%A4%A7%E7%9A%84%E6%88%90%E9%95%BF%EF%BC%8C%E9%99%A4%E4%BA%86%E7%A7%AF%E7%B4%AF%E5%8E%9F%E7%94%9FJavaScript%E7%9A%84%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86%EF%BC%8C%E8%BF%98%E6%98%AF%E6%9C%89%E5%BF%85%E8%A6%81%E6%8E%8C%E6%8F%A1%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91%E7%9A%84%EF%BC%8C%E8%BF%99%E6%A0%B7%E6%98%AF%E4%BB%8E%E4%B8%80%E4%B8%AA%E5%85%A8%E7%AB%AF%E5%BC%80%E5%8F%91%E5%B7%A5%E7%A8%8B%E5%B8%88%E5%BD%BB%E5%BA%95%E8%BD%AC%E5%8F%98%E6%88%90%E5%A4%A7%E5%89%8D%E7%AB%AF%E7%9A%84%E4%B8%80%E4%B8%AA%E5%BF%85%E7%BB%8F%E4%B9%8B%E8%B7%AF%EF%BC%81"><span class="toc-number">1.0.0.0.1.</span> <span class="toc-text">作为一名热爱学习的前端工程师，想要获得更大的成长，除了积累原生JavaScript的相关知识，还是有必要掌握后端开发的，这样是从一个全端开发工程师彻底转变成大前端的一个必经之路！</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E8%83%8C%E6%99%AF"><span class="toc-number">1.1.</span> <span class="toc-text">项目背景</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8A%80%E6%9C%AF%E6%9E%B6%E6%9E%84"><span class="toc-number">1.2.</span> <span class="toc-text">技术架构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8A%80%E6%9C%AF%E6%9E%B6%E6%9E%84%E8%AF%B4%E6%98%8E"><span class="toc-number">1.2.1.</span> <span class="toc-text">技术架构说明</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%8A%E9%9D%A2%E5%B0%B1%E6%98%AF%E6%88%91%E4%BB%ACweb%E6%9C%8D%E5%8A%A1%E7%AB%AF%E4%B8%BB%E8%A6%81%E4%BD%BF%E7%94%A8%E7%9A%84%E4%B8%AD%E9%97%B4%E4%BB%B6%EF%BC%8C%E5%AF%B9%E4%BA%8E%E6%AF%8F%E4%B8%80%E5%9D%97%E5%A6%82%E4%BD%95%E5%8E%BB%E7%BB%84%E7%BB%87%E5%92%8C%E6%9E%B6%E6%9E%84%EF%BC%8C%E5%8C%85%E6%8B%AC%E8%87%AA%E5%B7%B1%E5%AE%9E%E7%8E%B0%E9%94%99%E8%AF%AF%E6%A0%A1%E9%AA%8C%E4%B8%AD%E9%97%B4%E4%BB%B6%EF%BC%8C%E6%88%91%E4%BC%9A%E5%9C%A8%E5%90%8E%E9%9D%A2%E4%B8%80%E4%B8%80%E4%BB%8B%E7%BB%8D%EF%BC%8C%E7%94%B1%E4%BA%8E%E5%86%99%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%9A%84%E8%BF%87%E7%A8%8B%E4%B8%AD%E4%B9%9F%E6%9F%A5%E9%98%85%E4%BA%86%E5%BE%88%E5%A4%9A%E8%B5%84%E6%96%99%EF%BC%8C%E5%A6%82%E6%9C%89%E4%B8%8D%E8%B6%B3%E6%88%96%E9%9C%80%E8%A6%81%E4%BC%98%E5%8C%96%E7%9A%84%E5%9C%B0%E6%96%B9%EF%BC%8C%E6%AC%A2%E8%BF%8E%E4%BA%A4%E6%B5%81%E3%80%82"><span class="toc-number">1.2.1.0.1.</span> <span class="toc-text">上面就是我们web服务端主要使用的中间件，对于每一块如何去组织和架构，包括自己实现错误校验中间件，我会在后面一一介绍，由于写服务端的过程中也查阅了很多资料，如有不足或需要优化的地方，欢迎交流。</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">1.2.2.</span> <span class="toc-text"></span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E5%BD%95"><span class="toc-number">1.2.3.</span> <span class="toc-text">目录</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD%E7%B2%BE%E8%AE%B2"><span class="toc-number">1.3.</span> <span class="toc-text">常用功能精讲</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#sequelize"><span class="toc-number">1.3.1.</span> <span class="toc-text">sequelize</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#supervisor"><span class="toc-number">1.3.2.</span> <span class="toc-text">supervisor</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%89%93%E5%8C%85%E4%B8%8A%E7%BA%BF-%E6%89%93%E5%8C%85%E6%88%90%E5%BA%94%E7%94%A8"><span class="toc-number">1.4.</span> <span class="toc-text">打包上线&#x2F;打包成应用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E7%A8%8B%E5%B8%B8%E9%A9%BBpm2"><span class="toc-number">1.4.1.</span> <span class="toc-text">进程常驻pm2</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#mysql%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E5%8A%9F%E8%83%BD%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86"><span class="toc-number">1.4.2.</span> <span class="toc-text">mysql数据库连接功能相关知识</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#docker%E6%89%93%E5%8C%85%E9%95%9C%E5%83%8F"><span class="toc-number">1.4.3.</span> <span class="toc-text">docker打包镜像</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86-uglify-es%E6%B7%B7%E6%B7%86"><span class="toc-number">1.4.4.</span> <span class="toc-text">代码混淆 uglify-es混淆</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99"><span class="toc-number">1.4.5.</span> <span class="toc-text">参考资料</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/csjakjkse/" title="【原创】ThreeJsModelViewer三维模型查看器"><img src= "" data-lazy-src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d45b38343354480eb08f72a3f2f19082~tplv-k3u1fbpfcp-zoom-crop-mark:1512:1512:1512:851.awebp?" onerror="this.onerror=null;this.src='/assets/img/404.jpg'" alt="【原创】ThreeJsModelViewer三维模型查看器"/></a><div class="content"><a class="title" href="/posts/csjakjkse/" title="【原创】ThreeJsModelViewer三维模型查看器">【原创】ThreeJsModelViewer三维模型查看器</a><time datetime="2023-03-03T09:04:04.175Z" title="发表于 2023-03-03 17:04:04">2023-03-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/adsdsafc/" title="【原创】WUI云桌面系统"><img src= "" data-lazy-src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/69acd21462774eb5bb724268d0a613ce~tplv-k3u1fbpfcp-watermark.image?" onerror="this.onerror=null;this.src='/assets/img/404.jpg'" alt="【原创】WUI云桌面系统"/></a><div class="content"><a class="title" href="/posts/adsdsafc/" title="【原创】WUI云桌面系统">【原创】WUI云桌面系统</a><time datetime="2023-03-03T08:43:54.571Z" title="发表于 2023-03-03 16:43:54">2023-03-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/21cfbf15/" title="【原创】基于Uniapp和UniCloud开发的全栈博客项目3.0"><img src= "" data-lazy-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9213dfdc9fdd4958b7f2439f068c8edf~tplv-k3u1fbpfcp-zoom-crop-mark:1512:1512:1512:851.awebp?" onerror="this.onerror=null;this.src='/assets/img/404.jpg'" alt="【原创】基于Uniapp和UniCloud开发的全栈博客项目3.0"/></a><div class="content"><a class="title" href="/posts/21cfbf15/" title="【原创】基于Uniapp和UniCloud开发的全栈博客项目3.0">【原创】基于Uniapp和UniCloud开发的全栈博客项目3.0</a><time datetime="2023-03-03T07:54:11.519Z" title="发表于 2023-03-03 15:54:11">2023-03-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/undefined/" title="【转载】我在工作中是如何使用 git 的 - 掘金"><img src= "" data-lazy-src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8768f3a464a64596abbce522a8acd54f~tplv-k3u1fbpfcp-zoom-crop-mark:3024:3024:3024:1702.awebp" onerror="this.onerror=null;this.src='/assets/img/404.jpg'" alt="【转载】我在工作中是如何使用 git 的 - 掘金"/></a><div class="content"><a class="title" href="/posts/undefined/" title="【转载】我在工作中是如何使用 git 的 - 掘金">【转载】我在工作中是如何使用 git 的 - 掘金</a><time datetime="2023-03-02T02:20:09.596Z" title="发表于 2023-03-02 10:20:09">2023-03-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/undefined/" title="【转载】如何封装一个高质量的表单通用组件？ - 掘金"><img src= "" data-lazy-src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/aa0d64c2e4344210b451e9030c953d1a~tplv-k3u1fbpfcp-zoom-crop-mark:3024:3024:3024:1702.awebp?" onerror="this.onerror=null;this.src='/assets/img/404.jpg'" alt="【转载】如何封装一个高质量的表单通用组件？ - 掘金"/></a><div class="content"><a class="title" href="/posts/undefined/" title="【转载】如何封装一个高质量的表单通用组件？ - 掘金">【转载】如何封装一个高质量的表单通用组件？ - 掘金</a><time datetime="2023-03-02T02:15:38.710Z" title="发表于 2023-03-02 10:15:38">2023-03-02</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/03f34d3f6f914347905ce6e7a2f5a4b1~tplv-k3u1fbpfcp-zoom-1.image')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 凡尘</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"><script>function loadLivere () {
  if (typeof LivereTower === 'object') {
    window.LivereTower.init()
  }
  else {
    (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
    })(document, 'script');
  }
}

if ('Livere' === 'Livere' || !true) {
  if (true) btf.loadComment(document.getElementById('lv-container'), loadLivere)
  else loadLivere()
}
else {
  function loadOtherComment () {
    loadLivere()
  }
}</script></div><div class="aplayer no-destroy" data-id="60198" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"> </div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div><script src="https://cdn.jsdelivr.net/npm/live2d-widget@^3.1.3/lib/L2Dwidget.min.js"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/miku.model.json"},"display":{"position":"left","width":200,"height":400},"mobile":{"show":false},"log":false});</script></body></html>